package com.sskj.hangqing.ui.activity;


import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.hangqing.R;
import com.sskj.hangqing.R2;
import com.sskj.hangqing.bean.GuideListBean;
import com.sskj.hangqing.presenter.GuideWebActivityPresenter;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.zzhoujay.richtext.RichText;

import butterknife.BindView;

@Route(path = RConfig.APP_GUIDE_WEB)
public class GuideWebActivity extends BaseActivity<GuideWebActivityPresenter> {
    @BindView(R2.id.tvContent)
    TextView tvContent;

    @Autowired
    String content;
    @Autowired
    String time;
    @Autowired
    String title;
    @Autowired
    String id;
    @Autowired
    String head;
    @Autowired
    boolean isZixun;//咨询
    @Autowired
    boolean isAboutUs;//关于我们
    @Autowired
    boolean isGonggao;//公告
    @Autowired
    boolean isRegister;//注册协议
    @BindView(R2.id.tvWebTitle)
    TextView tvWebTitle;
    @BindView(R2.id.tvTime)
    TextView tvTime;


    @Override
    protected int getLayoutId() {
        return R.layout.app_activity_guide_web;
    }

    @Override
    public GuideWebActivityPresenter getPresenter() {
        return new GuideWebActivityPresenter();
    }

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        setTitle(head);

        if (!TextUtils.isEmpty(id)) {
            mPresenter.getContent(id);
        }

        if (isZixun) {
            setTitle(App.INSTANCE.getString(R.string.hang_guideWebActivity1));
            updateZixun();
        }
        if (isAboutUs) {
            setTitle(App.INSTANCE.getString(R.string.hang_guideWebActivity2));
            tvWebTitle.setText("LA COIN");
            tvTime.setVisibility(View.GONE);
            mPresenter.getAboutUs();
        }
        if (isGonggao) {
            tvWebTitle.setGravity(Gravity.LEFT);
            setTitle(App.INSTANCE.getString(R.string.hang_guideWebActivity3));
            updateZixun();
        }
        if (isRegister) {
            setTitle(App.INSTANCE.getString(R.string.hang_guideWebActivity4));
            tvWebTitle.setVisibility(View.GONE);
            tvTime.setVisibility(View.GONE);
            mPresenter.getRegister();
        }

    }

    private void updateZixun() {
        tvWebTitle.setText(title);
        tvTime.setText(time);
        updateUI();

    }

    public void updateUI() {
        if (TextUtils.isEmpty(content)) {
            return;
        }
        RichText.from(content).into(tvContent);
    }


    public void getContentSuccess(GuideListBean data) {
        content = data.getContent();
        time = data.getPublish_time();
        title = data.getTitle();
        tvWebTitle.setText(title);
        tvTime.setText(time);
        updateUI();
    }

    public void updateContent(String data) {
        this.content = data;
        updateUI();
    }
}
